package jzqb.service.impl;

import haha.life.common.SysTool;
import haha.life.normal.FileUtil;
import haha.life.normal.FileuploadUtils;
import jzqb.bo.IndexBo;
import jzqb.bo.IndexLoopBo;
import jzqb.bo.StandardBo;
import jzqb.dao.IndexDao;
import jzqb.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2020-09-22
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    IndexDao indexDao;

    @Value("${filePath.qbcgCoverPath}")
    private String qbcgCoverPath;

    @Override
    public List<IndexBo> getLoopReult() {
        List<IndexBo> indexBos = new ArrayList<>();
        IndexBo SB = new IndexBo(SysTool.SB);
        IndexBo TX = new IndexBo(SysTool.TX);
        IndexBo SP = new IndexBo(SysTool.SP);
        IndexBo KG = new IndexBo(SysTool.KG);
        IndexBo TC = new IndexBo(SysTool.TC);
        IndexBo FK = new IndexBo(SysTool.FK);
        IndexBo DZ = new IndexBo(SysTool.DZ);
        IndexBo QT = new IndexBo(SysTool.QT);
        indexBos.add(SB);
        indexBos.add(TX);
        indexBos.add(SP);
        indexBos.add(KG);
        indexBos.add(TC);
        indexBos.add(FK);
        indexBos.add(DZ);
        indexBos.add(QT);
        for (IndexBo indexBo : indexBos) {
            List<IndexLoopBo> standardBos = indexDao.getIndexLooP(indexBo);
            indexBo.setArrList(standardBos);
        }
        return indexBos;
    }

    @Override
    public List<StandardBo> researchResult() {
        List<StandardBo> standardBos = indexDao.researchResult();
        for (StandardBo standardBo : standardBos) {
            String cover = standardBo.getCoverPage();
            if ("".equals(cover) || cover == null) {
                standardBo.setCoverByte(null);
            } else {
                String path = FileUtil.calculateAbstractPath(cover, qbcgCoverPath);
                standardBo.setCoverPath(path);
            }
        }
        return standardBos;
    }
}